package site.zhoulei.springbootstu.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * 测试swagger接口文档
 * @author zlleige
 * @create 2020-07-30 9:45
 */
@Configuration //@Configuration用于定义配置类，可替换xml配置文件，被注解的类内部包含有一个或多个被@Bean注解的方法，这些方法将会被AnnotationConfigApplicationContext或AnnotationConfigWebApplicationContext类进行扫描，并用于构建bean定义，初始化Spring容器。
@EnableSwagger2
public class Swagger2 {
    private ApiInfo apiInfo(){
        return new ApiInfoBuilder()
                .title("springboot 利用swagger构建api文档")
                .description("简单优雅的restful风格")
                .termsOfServiceUrl("https://zhoulei.site")
                .version("1.0")
                .build();
    }

    @Bean
    public Docket createRestApi(){
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                //扫描basePackage包下面的"/rest/"路径下的内容作为借口文档构建的目标
                .apis(RequestHandlerSelectors.basePackage("site.zhoulei.springbootstu"))
                .paths(PathSelectors.regex("/rest/.*"))
                .build();
    }

}
